package com.ftg.learn.springboot.comment.controller;

import com.ftg.learn.springboot.comment.pojo.comment;
import com.ftg.learn.springboot.comment.service.commentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

@RequestMapping("comment")
@CrossOrigin
@RestController
public class commentController {

	@Autowired
	commentService cs;

	@PostMapping("/add")
	public int addComment(comment comment){

		comment.setCid(UUID.randomUUID().toString());
		return cs.addComment(comment);
	}

	@GetMapping("/show")
	public Map<String , Object> show(){
		Map<String , Object> map = new HashMap<>();

		map.put("data",cs.showAA());
		map.put("count",cs.countall());
		return map;
	}

	@PostMapping("/rand")
	public int pageView(){
		return cs.pageView();
	}

	//查个数
	@GetMapping("/countc")
	public int countall(){
		return  cs.countall();
	}

	@GetMapping("/randomComment")
	public Map<String , Object> randomComment(){

		Map<String, Object> map = new HashMap<>();
		List<comment> list = cs.randomComment();
		map.put("data",list);
		map.put("core",0);
		return map;

	}

	@PostMapping("/addContactByBname")
	public int addContactByBname(comment comment) {
		int list = cs.findBidcountByBname(comment.getBname());

		if (list == 0) {
			return 0;
		} else return cs.addCommentByBname(comment);

	}
}
